package sort;

public class MergeTwoArray {

	public static void main(String[] args) {
		int[] a = new int[6];
		a[0] = 2;
		a[1] = 4;
		a[2] = 6;
		int[] b = { 1, 3, 5 };
		merge(a, 3, b, 3);
		for (int i : a) {
			System.out.print(i + " ");
		}
	}

	public static void merge(int[] a, int len1, int[] b, int len2) {
		int index = a.length - 1;
		len1--;
		len2--;
		while (len2 >= 0 && len1 >= 0) {
			a[index--] = a[len1] > b[len2] ? a[len1--] : b[len2--];

		}
		while (len2 >= 0) {
			a[index--] = b[len2--];
		}
	}
}
